﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DCSLibrary;
using Telerik.Web.UI;
using Utils.DatabaseUtils;
using Utils.DC.Web.UI;
using Utils;
using System.Collections;

public partial class Admin_Module_quan_tri_bai_viet : System.Web.UI.UserControl
{
    private string newsType;

    public string NewsType
    {
        get { return newsType; }
        set { newsType = value; }
    }

    #region Cac bien dung chung

    NewsUI objNews = new NewsUI();
    DataSet dsNews;

    #endregion

    #region Cac Ham Su Kien

    protected void Page_Load(object sender, EventArgs e)
    {
        dsNews = objNews.GetAll();
        if (!IsPostBack)
        {
            BindGrid();
            
        }
    }

    protected void News_Delete(object sender, EventArgs e)
    {
        try
        {
            LinkButton button = (LinkButton)sender;
            int result = objNews.DeleteByID(Convert.ToInt32(button.CommandArgument));
            if (result > 0)
            {
                //Response.Write(messageBox.Alert(MessageBox.MESSAGE_ADD_SUCCESSFULLY));
                lblMessage.Text = MessageBox.MESSAGE_DELETE_SUCCESSFULLY;
                BindGrid();
            }
            else
            {
                //Response.Write(messageBox.Alert(MessageBox.MESSAGE_ADD_NOT_SUCCESSFULLY));
                lblMessage.Text = MessageBox.MESSAGE_DELETE_NOT_SUCCESSFULLY;
            }
        }
        catch (Exception ex)
        {
            lblMessage.Text = MessageBox.MESSAGE_CONFILCT_DATA;
        }
    }

    protected void Ajax_Request(object sender, AjaxRequestEventArgs e)
    {
        if (e.Argument == "Rebind")
        {
            dsNews = objNews.GetAll();
            BindGrid();
        }
    }
       
    #endregion

    #region Cac Ham Tuong Tac Du Lieu

    private void BindGrid()
    {
        if (TableLib.HasData(dsNews))
        {
            //DataTable dt = TableLib.CreateTable(dsNews.Tables[0], "NewsType = '" + newsType + "'");
            grd.DataSource = dsNews.Tables[0];
            grd.DataBind();
        }
    }

    #endregion
}
